#include <bits/stdc++.h>

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; i++)
#define _rep(i, a, b) for (int i = (a), i##end = (b); i >= i##end; i--)
#define dl make_pair
#define dk(...) make_tuple(__VA_ARGS__)
#define ec first
#define fb second
#define de(x) cerr << #x << " = " << (x) << endl

using namespace std;

typedef long long ll;
typedef __int128 i128;
typedef pair <int, int> pii;

int read() {
	int x = 0, w = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') w = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + (ch ^ 48);
		ch = getchar();
	}
	return x * w;
}

template <typename _Tp>
void print(_Tp x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) print(x / 10);
	putchar(x % 10 + 48);
}

const int MAXN = 1e5 + 5;
int T, n, a[MAXN], deg[MAXN];

struct point {
	int id;

	point(int _id) { id = _id; }

	bool operator < (const point &t) const { return a[id] > a[t.id]; }
};

map <int, set <point> > _G;
vector <point> G[MAXN];
int root, rm[MAXN], flg;

void dfs(int u, int fa) {
	if (deg[u] == 1) return;
	for (auto [v] : G[u]) {
		dfs(v, u);
		if (flg) return;
	}
	int sum = 0;
	sort(G[u].begin(), G[u].end());
	for (auto it = next(G[u].begin()); it != G[u].end(); it++) {
		sum += a[it -> id];
	}
	a[u] -= sum;
	a[G[u].begin() -> id] -= sum;
	if (a[u] != a[G[u].begin() -> id]) {
		puts("NO");
		flg = 1;
		return;
	}
}

void solve() {
	n = read();
	flg = 0;
	_G.clear();
	rep (i, 1, n) deg[i] = rm[i] = 0, G[i].clear();
	rep (i, 1, n) a[i] = read();
	rep (i, 1, n - 1) {
		int u = read(), v = read();
		_G[u].emplace(v);
		_G[v].emplace(u);
		deg[u]++, deg[v]++;
	}
	root = -1;
	rep (i, 1, n) if (deg[i] > 1 && !rm[i]) { root = i; break; }
	if (root == -1) {
		
		return;
	}
	rep (i, 1, n) {
		if (rm[i]) continue;
		for (auto [v] : _G[i]) G[i].push_back(v), cout << i << " -> " << v << endl;
	}
	de(root);
	dfs(root, 0);
	if (flg) return;
	if (a[root] == 0) puts("YES");
	else puts("NO");
}

int main() {
#ifndef LOCAL
	freopen("clean.in", "r", stdin);
	freopen("clean.out", "w", stdout);
#endif
	T = read();
	while (T --> 0) solve();
	return 0;
}
